package com.example.recyclerviewdemo

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ImageView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.recyclerviewdemo.demo0.Demo0Activity
import com.example.recyclerviewdemo.diffdemo.DiffDemoActivity
import com.example.recyclerviewdemo.layoutmanager.LayoutManagerActivity
import com.example.recyclerviewdemo.tree.TreeActivity

class MainActivity : AppCompatActivity() {

    private val mainAdapter by lazy {
        MainAdapter(this)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        initRv()
    }

    private fun initRv() {

        val mutableListOf = mutableListOf<String>().apply {
            add("demo0:基础使用")
            add("demo1:DiffUtil")
            add("demo2:LayoutManager")
            add("TreeList")
        }
        mainAdapter.setNewList(mutableListOf)
        mainAdapter.setMainAdapterListener(object :MainAdapterListener{
            override fun clickItems(position: Int) {
                when(position){
                    0 ->{
                        startActivity(Intent(this@MainActivity,Demo0Activity::class.java))
                    }
                    1 ->{
                        startActivity(Intent(this@MainActivity, DiffDemoActivity::class.java))
                    }
                    2 ->{
                        startActivity(Intent(this@MainActivity, LayoutManagerActivity::class.java))
                    }
                    3 ->{
                        startActivity(Intent(this@MainActivity, TreeActivity::class.java))
                    }
                }

            }

        })

        val recyclerView = findViewById<RecyclerView>(R.id.recyclerView)

        recyclerView.layoutManager = LinearLayoutManager(this)
        recyclerView.adapter = mainAdapter

    }
}